﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Repositories;

namespace Himp.Platform.Dc
{
    /// <summary>
    /// 中医证候
    /// </summary>
    public class TcmsympDictService : DcAppService
    {
        private readonly IRepository<TcmsympDict, Guid> _tcmsympDictRepository;

        public TcmsympDictService(IRepository<TcmsympDict, Guid> tcmsympDictRepository)
        {
            _tcmsympDictRepository = tcmsympDictRepository;
        }

        /// <summary>
        /// 获取诊断列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<PagedResultDto<TcmsympDictDto>> GetListAsync(TcmsympDictInput input)
        {
            var iQuery = await _tcmsympDictRepository.GetQueryableAsync();
            iQuery = iQuery.WhereIf(!string.IsNullOrEmpty(input.Key), d => d.TcmsympName.Contains(input.Key));

            if (input.SkipCount == 0)
            {
                var itemsDto = ObjectMapper.Map<List<TcmsympDict>, List<TcmsympDictDto>>(iQuery.ToList());

                return new PagedResultDto<TcmsympDictDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.SkipCount, input.MaxResultCount);
                var itemsDto = ObjectMapper.Map<List<TcmsympDict>, List<TcmsympDictDto>>(items.ToList());

                return new PagedResultDto<TcmsympDictDto>(totalCount, itemsDto);
            }
        }
    }
}
